<?php
#basado en: http://snippets.symfony-project.org/snippet/353
class sfChangeAppRoute extends sfRoute {

  public function generate($params, $context = array(), $absolute = true)
  {
    if(!array_key_exists('app',$params))
        return parent::generate($params, $context, $absolute);

    $app_name=sfContext::getInstance()->getConfiguration()->getApplication();
    $env_name=sfContext::getInstance()->getConfiguration()->getEnvironment();
    if($env_name=='prod')
        $env='';        
    else
        $env='_'.$env_name;


    if($params['app']=='frontend' && !$env)
        $app_destino = 'index';
    else
        $app_destino = $params['app'];


    if(array_key_exists('sf_module',$params) && array_key_exists('sf_action',$params))
        $moduloYaccion = '/'.$params['sf_module'].'/'.$params['sf_action'];
    else
        $moduloYaccion = '';

    $url='/../'.$app_destino.$env.'.php'.$moduloYaccion;

    return $url;
  }

}